package com.ruoyi.web.controller.finance;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.finance.domain.AccountsPayable;
import com.ruoyi.finance.service.IAccountsPayableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 应付账款Controller
 * 
 * @author liuyu
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/finance/payable")
public class AccountsPayableController extends BaseController
{
    @Autowired
    private IAccountsPayableService accountsPayableService;

    /**
     * 查询应付账款列表
     */
    @PreAuthorize("@ss.hasPermi('finance:payable:list')")
    @GetMapping("/list")
    public TableDataInfo list(AccountsPayable accountsPayable)
    {
        startPage();
        List<AccountsPayable> list = accountsPayableService.selectAccountsPayableList(accountsPayable);
        return getDataTable(list);
    }

    /**
     * 导出应付账款列表
     */
    @PreAuthorize("@ss.hasPermi('finance:payable:export')")
    @Log(title = "应付账款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountsPayable accountsPayable)
    {
        List<AccountsPayable> list = accountsPayableService.selectAccountsPayableList(accountsPayable);
        ExcelUtil<AccountsPayable> util = new ExcelUtil<AccountsPayable>(AccountsPayable.class);
        util.exportExcel(response, list, "应付账款数据");
    }

    /**
     * 获取应付账款详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:payable:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(accountsPayableService.selectAccountsPayableById(id));
    }

    /**
     * 新增应付账款
     */
    @PreAuthorize("@ss.hasPermi('finance:payable:add')")
    @Log(title = "应付账款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountsPayable accountsPayable)
    {
        return toAjax(accountsPayableService.insertAccountsPayable(accountsPayable));
    }

    /**
     * 修改应付账款
     */
    @PreAuthorize("@ss.hasPermi('finance:payable:edit')")
    @Log(title = "应付账款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountsPayable accountsPayable)
    {
        return toAjax(accountsPayableService.updateAccountsPayable(accountsPayable));
    }

}